package cn.jisol.ngame.rpc.action;

import lombok.Getter;
import lombok.Setter;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 网络回调
 */
@Getter
@Setter
public class NBackAsync<T extends Object> {
    
    NBack<T> nBack;
    Type rType;
    
    public NBackAsync(){
        this.nBack = (T data) -> {};
    }
    
    public NBackAsync(NBack<T> nBack) {
        this.nBack = nBack;
    }
    
    public NBackAsync<T> async(NBack<T> back){
        this.nBack = back;
        return this;
    }
    
    //调用
    public void emit(T data){
        this.nBack.none(data);
    }
    
    public Class<T> getReturnType() {
        ParameterizedType parameterizedType = (ParameterizedType) this.getClass().getGenericSuperclass();
        return (Class<T>) parameterizedType.getActualTypeArguments()[0];
    }

    public interface NBack<T>{
        public void none(T data);
    }
    
}
